import java.util.concurrent.Semaphore;


public class RAM {
	public static String[] Address = new String[Driver.RAM_SIZE];
	public static Semaphore s = new Semaphore(1, true);
	public static void write(int address, String data){
		try {
			s.acquire();
				Address[address] = data;			
			s.release();
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		}
		
	}
	
	public static String read(int address){
		return Address[address];
	}
	
	public static void write(int address, long l) {
		String value = Long.toHexString(l);
		if (value.length()<8)
			value = Convert.stringOfChars('0', 8 - value.length()) + value;
		write (address, value);
		
	}
	
	public static void lock(){
		try {
			s.acquire();
		} catch (InterruptedException e) {			
			e.printStackTrace();
		}
	}
	
	public static void release(){
		s.release();
	}
	
}
